package net.mingsoft.dashboard.action.web;

import com.alibaba.druid.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.dashboard.action.q.contact.MyEmailQuery;
import net.mingsoft.dashboard.action.q.contact.MyPhoneQuery;
import net.mingsoft.dashboard.action.q.contact.SendCodeQuery;
import net.mingsoft.dashboard.action.r.MyContactDetailResponse;
import net.mingsoft.dashboard.biz.MyContactBiz;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author gengfa
 * @date 22/01/26
 */
@Api(value = "个人联系方式", tags = {"工作台-个人联系方式"})
@Controller("WebMyContactAction")
@RequestMapping("/${ms.manager.path}/mycontact")
public class MyContactAction {

    @Resource
    MyContactBiz contactBiz;

    @ApiOperation(value = "我的联系方式详情")
    @GetMapping(value = "/detail")
    @ResponseBody
    public ResultData detail() {
        MyContactDetailResponse detail = contactBiz.getMyDetail();
        return ResultData.build().success(detail);
    }

    @ApiOperation(value = "手机号绑定")
    @GetMapping(value = "/bind/mobile")
    @ResponseBody
    public ResultData bindPhone(@RequestParam String mobile, @RequestParam String code) {
        MyPhoneQuery query = new MyPhoneQuery().setCode(code).setMobile(mobile);
        return ResultData.build().success(contactBiz.bindMobile(query));
    }

    @ApiOperation(value = "邮箱绑定")
    @GetMapping(value = "/bind/email")
    @ResponseBody
    public ResultData bindEmail(@RequestParam String email, @RequestParam String code) {
        MyEmailQuery query = new MyEmailQuery().setCode(code).setEmail(email);
        return ResultData.build().success(contactBiz.bindEmail(query));
    }

    @ApiOperation(value = "发送验证码")
    @GetMapping(value = "/send/code")
    @ResponseBody
    private ResultData sendCode(@RequestParam String type, @RequestParam String receiver) {
        SendCodeQuery query = new SendCodeQuery().setReceiver(receiver).setType(type);
        return ResultData.build().success(contactBiz.sendCode(query));
    }
}
